package com.bootlever.rmi.server.controller;

import com.bootlever.framework.rmi.templates.RmiTemplate;
import com.bootlever.rmi.user.sdk.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class TestRmiController {

    @Autowired
    private RmiTemplate rmiTemplate;

    private static final Logger logger = LoggerFactory.getLogger(TestRmiController.class);


    @RequestMapping(value = "/testrmi")
    public String testRmi() throws Exception {
        //com.mchange.v2.c3p0.QueryConnectionTester;
        //com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
        //com.ibatis.sqlmap.engine.impl.SqlMapClientImpl
        UserService userService = (UserService) rmiTemplate.get(UserService.class);
        String name = userService.getUserName(0);
        logger.info("得到结果{}", name);
        return "测试成功";
    }

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/testrmi2")
    public String testRmi2() throws Exception {
        logger.info("注入方式");
        String name = userService.getUserName(0);
        logger.info("得到结果{}", name);
        return "测试成功";
    }
}
